package com.sohu.sip.cds.dao.hibernate;

import java.util.List;

import org.hibernate.Session;

import com.sohu.peak.util.HibernateHelper;
import com.sohu.peak.util.Logger;
import com.sohu.peak.util.Pagination;
import com.sohu.peak.util.PeakSessionFactory;
import com.sohu.sip.cds.dao.RegionDao;
import com.sohu.sip.cds.model.Region;

public class RegionDaoHibernate implements RegionDao {

	public void deleteRegion(Region region) {
		Session session = PeakSessionFactory.instance().getCurrentSession();
		session.delete(region);
	}

	public Region getRegion(Long id) {
		Session session = PeakSessionFactory.instance().getCurrentSession();
		return (Region) session.get(Region.class, id);
	}

	public List<Region> getRegionList(Pagination pagination, int status) {
		String queryHql = " from Region where status = ?  order by updateTime desc ";

		Object[] params = { new Integer(status) };
		Session session = PeakSessionFactory.instance().getCurrentSession();

		List<Region> RenderList = (List<Region>) HibernateHelper.pageQuery(session, session
				.createQuery(queryHql), pagination, params);

		return RenderList;
	}

	public void saveRegion(Region region) {
		Session session = PeakSessionFactory.instance().getCurrentSession();
		session.save(region);

	}

	public void updateRegion(Region region) {
		Session session = PeakSessionFactory.instance().getCurrentSession();
		session.update(region);

	}

}
